const express = require('express');
const controller = require('../controller')
const router = express.Router();
const multer = require('multer');
const upload = multer({dest:"/"});

router.get('/test', function(req, res, next) {
  res.send(`${process.pid}`);
  res.end();
});

router.get('/', controller.simpleAuth, controller.index)

router.post('/login', controller.login)

router.get('/file/list', controller.fileList);

router.get('/imgPath', controller.imgPath);

router.get('/search', controller.searchFun);

router.post('/', upload.any(), controller.uploadFun);

// 成品接口，支持点击进度条播放
router.get('/getVideo', controller.getVideo);

// 因为getVideo是以流的方式给前端返回，所以前端并不知道视频的总时长，只能是返回一节，video标签就加上返回的时长，所以通过该接口获取到原视频的时长
router.get('/getDuration', controller.getDuration);

// 返回公钥文件内容的接口
router.get('/public', controller.getPemFile);

router.get('/encrypt.key', controller.getKeyFile);

// 返回 m3u8 文件的接口
router.post('/encrypt/:videoName/play', controller.getEncryptVideoM3u8);

// 返回 playlist.ts 文件流的接口
router.post('/playback', controller.getTsPlayList);

module.exports = router;
